package cn.getech.data.metadata.service.impl;

import cn.getech.data.intelligence.common.exception.RRException;
import cn.getech.data.metadata.entity.CollectionTableBusinessDescriptionEntity;
import cn.getech.data.metadata.mapper.CollectionTableBusinessDescriptionMapper;
import cn.getech.data.metadata.model.req.collectiontablefield.CollectiionTableFieldListReq;
import cn.getech.data.metadata.service.CollectionTableBusinessDescriptionService;
import cn.getech.data.metadata.service.CollectionTableField2Service;
import cn.getech.system.center.utils.ShiroUtils;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;


@Service
public class CollectionTableBusinessDescriptionServiceImpl extends ServiceImpl<CollectionTableBusinessDescriptionMapper,CollectionTableBusinessDescriptionEntity> implements CollectionTableBusinessDescriptionService {

    @Autowired
    private CollectionTableField2Service collectionTableField2Service;

    @Autowired
    private CollectionTableBusinessDescriptionMapper collectionTableBusinessDescriptionMapper;

    @Override
    public boolean editMetadataDetails(Map<String,Object>  params){
        String user_id = ShiroUtils.getUserId().toString();
        String table_id = params.get("table_id").toString();

        int userId=Integer.parseInt(user_id);
        int tableId = Integer.parseInt(table_id);

        HashMap<String,Integer>  collectiionTableFieldListReq = new HashMap();
        collectiionTableFieldListReq.put("user_id",userId);
        collectiionTableFieldListReq.put("table_id",tableId);

        // 判断是否有编辑权限，1：有编辑权限
            // 1 通过传入的table_id 判断数据库的表中是否存在数据，如果存在，则更新，否则插入新数据
           if(collectionTableBusinessDescriptionMapper.selectByTableId(tableId)!= null ){
               // 更新操作
               collectionTableBusinessDescriptionMapper.updateByTableId(params);
               return true;
           }else{
               // 插入操作
               collectionTableBusinessDescriptionMapper.insertByTableId(params);
               return true;
           }


    }

    @Override
    public CollectionTableBusinessDescriptionEntity selectDescription(Map<String,Object>  params){
        if(params.get("table_id") != null){
            CollectionTableBusinessDescriptionEntity DescriptionEntities = collectionTableBusinessDescriptionMapper.selectDescription(params);
            return DescriptionEntities;
        }else{
            throw new RRException("请输入表编号");
        }
    }




}
